/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    bool isPalindrome(ListNode* head) {
        string str;
        while(head)
        {
            str+=to_string(head->val);
            head=head->next;
        }
        int n=str.size();
        if(n==0)return false;
        if(n==1) return true;
        if(n%2==0)
        {
            int mid=n/2;
            int left=mid-1,right=mid;
            while(left>=0&&right<n&&str[left]==str[right])
            {
                left--;
                right++;
            }
            if(left==-1) return true;
            return false;
        }
        else
        {
            int left=n/2,right=n/2;
            while(left>=0&&right<n&&str[left]==str[right])
            {
                left--;
                right++;
            }
            if(left==-1) return true;
            return false;

        }
        return false;
    }
};